﻿using System;
using System.Windows;
using System.Windows.Controls;
using ZFCNew.Code;
using ZFCNew.Controls;
using ZFCNew.Views;

namespace ZFCNew
{
    public partial class MainPage : UserControl
    {
        public static NotificationPopup NotificationPop { get; private set; }
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            NotificationPop = this.Notification;
            MainFrame.NavigationFailed += (s, d) =>
                                              {
                                                  NotificationPop.SetMessage
                    (
                    new NotificationData
                    {

                        Message = "Oops! They scored a goal against us! Refresh your browser if its all broken."
                    }
                    );
                                                  NotificationPop.ShowWithDelay();
                                              };
            if (IsolatedStorageHelper.IsFirstTime())
            {
                IsolatedStorageHelper.SetExistingUser();
                NotificationPop.SetMessage
                    (
                    new NotificationData
                        {
                            InternalLink = new InternalLink
                                               {
                                                   Name = "about page",
                                                   Url = "about"
                                               },
                            Message = "First time here? Check out the"
                        }
                    );
                NotificationPop.ShowWithDelay();
            }
        }


        private void NavigationTabSelected(object sender, RoutedEventArgs e)
        {
            var c = sender as Control;
            MainFrame.Navigate(new Uri(c.Tag.ToString(), UriKind.Relative));
        }

        private void MainFrame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                foreach (var nav in NavHolder.Children)
                {
                    var navBtn = (RadioButton)nav;
                    if (Utility.IsSimilarUrl(navBtn.Tag.ToString(), e.Uri.ToString()))
                    {
                        if (navBtn.IsChecked != true) navBtn.IsChecked = true;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                
            }
            
        }


        private void FeedbackClick(object sender, System.Windows.RoutedEventArgs e)
        {
            var feedbackWindow = new ZfcWindow();
            feedbackWindow.VerticalAlignment = VerticalAlignment.Top;
            feedbackWindow.Margin = new Thickness(0, 170, 0, 0);
            var fb = new Feedback();
            feedbackWindow.Content = fb;
            fb.CancelButton.Click += (s, a) => feedbackWindow.DialogResult = false;
            fb.OKButton.Click += (s, a) => feedbackWindow.DialogResult = true;
            feedbackWindow.Show();
        }



        private void DisplayDisclaimer(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var disclaimer = new ZfcWindow
            {
                Content = new Disclaimer(),
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, 70, 0, 0),

            };
            disclaimer.Show();
        }




    }
}